package com.tywj.buscustomerapp.view.myview;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.transition.Transition;
import com.tywj.buscustomerapp.Config;
import com.tywj.buscustomerapp.R;
import com.tywj.buscustomerapp.utils.ToastUtils;
import com.tywj.buscustomerapp.view.activity.MainActivity;
import com.tywj.buscustomerapp.view.activity.WebActivity;

public class TaylorImagWindow extends AlertDialog{

    private TaylorImageView img;
    private Context context;
    private String path;
    private String info;
    private TextView showInfo;

    public TaylorImagWindow(@NonNull Context context,String path,String info) {
        super(context);
        this.context = context;
        this.path = path;
        this.info = info;
    }

    public TaylorImagWindow(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
    }

    protected TaylorImagWindow(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener,String path) {
        super(context, cancelable, cancelListener);
        this.context = context;
        this.path = path;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pop_img_layout);
        img = findViewById(R.id.pop_img);
        showInfo = findViewById(R.id.show_info);
        WindowManager windowManager = getWindow().getWindowManager();
        int screenWidth = windowManager.getDefaultDisplay().getWidth();
        int screenHeight= windowManager.getDefaultDisplay().getHeight();
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        // 设置窗口背景透明度
        attributes.alpha = 1f;
        // 设置窗口宽高为屏幕的三分之一（为了更好地适配，请别直接写死）
        attributes.width = 4*screenWidth/5;
        attributes.height = 2*screenHeight/3;
        getWindow().setAttributes(attributes);
        getWindow().setWindowAnimations(R.style.take_photo_anim);
        initData();
        showInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (info!=null && !info.equals("null") && !info.equals("")){
                    Intent intent = new Intent(context,WebActivity.class);
                    intent.putExtra("url",info);
                    context.startActivity(intent);
                }else{
                    ToastUtils.show("暂无详情");
                }
            }
        });
    }

    private void initData() {
        if (path!=null && path.length()>0) {
            Glide.with(context).load(path).into(img).onLoadStarted(context.getResources().getDrawable(R.mipmap.iocn_bording));
        }
    }
}
